/*
 * FileName：Encodes.java 
 * <p>
 * Copyright (c) 2017-2020, <a href="http://www.webcsn.com">hermit (1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.primary.common.util;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringEscapeUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Random;


/**
 * @title : 
 * @description : 
 * @projectname : wxmp
 * @classname : Encodes
 * @version 1.0
 * @author : hermit
 * @createtime : 2017年11月4日 下午5:37:10
 */
public class InviteCode {

	private static final char[] CODE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
	private static final char[] NAME = "0123456789".toCharArray();

	/**
	 *获取邀请码
	 */
	public static String getName(int len) {
		StringBuffer str = new StringBuffer();
		Random random = new Random();
		int randomNum;
		for (int i = 0; i < len; i++) {
			// 可生成[0,n)之间的整数，获得随机位置
			randomNum = random.nextInt(NAME.length);
			// 组成一个随机字符串
			str.append(NAME[randomNum]);
		}
		return str.toString();
	}

	/**
	 *获取邀请码
	 */
	public static String getCode(int len) {
		StringBuffer str = new StringBuffer();
		Random random = new Random();
		int randomNum;
		for (int i = 0; i < len; i++) {
			// 可生成[0,n)之间的整数，获得随机位置
			randomNum = random.nextInt(CODE.length);
			// 组成一个随机字符串
			str.append(CODE[randomNum]);
		}
		return str.toString();
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for (int i = 0; i < 10000; i++){
			System.out.println(getName(8));
		}
	}

}
